<?php
class Pay_style_model extends CI_Model
{
    private $table = 'pay_style';
    
    public function find()
    {
        $this->db->where('pay_type', 'line');
        $this->db->order_by('order', 'asc');
        return $this->db->get($this->table);
    }
    
    public function total()
    {
        return $this->db->count_all_results($this->table);
    }
    
    public function page_list($num)
    {
        $this->db->order_by('id','desc');
        $this->db->limit(20, $num);
        return $this->db->get($this->table);
    }
    
    public function insertPayStyle($postData)
    {
        $data = array(
            'pay_name' => $postData['pay_name'],
            'pay_type' => $postData['pay_type'],
            'order'    => $postData['order'],
        );
    
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
    public function updatePayStyle($postData)
    {
        $data = array(
            'pay_name' => $postData['pay_name'],
            'order'    => $postData['order'],
        );
        $this->db->where('id', $postData['id']);
        return $this->db->update($this->table, $data);
    }
    
    public function findById($id)
    {
        $this->db->where('id', $id);
        return $this->db->get($this->table);
    }
}